﻿#pragma execution_character_set("utf-8")

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //打开
    openFileAction =new QAction(QIcon(":Open"),tr("打开"),this);
    openFileAction->setText(tr("打开"));
    openFileAction->setShortcut(tr("Ctrl+O"));
    openFileAction->setStatusTip(tr("打开一个文件"));
    connect(openFileAction,SIGNAL(triggered()),this,SLOT(ShowOpenFile()));

    //保存
    saveAction =new QAction(QIcon(":Save"),tr("保存"),this);
    saveAction->setText(tr("保存"));
    saveAction->setShortcut(tr("Ctrl+S"));
    saveAction->setStatusTip(tr("保存"));
    connect(saveAction,SIGNAL(triggered()),this,SLOT(onSaveFile()));

    //下一个
    nextAction =new QAction(QIcon(":Next"),tr("下一个"), this);
    nextAction->setStatusTip(tr("下一个"));
    connect(nextAction,SIGNAL(triggered()),this,SLOT(onNext()));

    //上一个
    preAction =new QAction(QIcon(":Pre"),tr("上一个"), this);
    preAction->setStatusTip(tr("上一个"));
    connect(preAction,SIGNAL(triggered()),this,SLOT(onPre()));

    //收藏
    esAction =new QAction(QIcon(":EnShrine"),tr("收藏"),this);
    esAction->setShortcut(tr("Ctrl+D"));
    esAction->setStatusTip(tr("收藏"));
    connect(esAction,SIGNAL(triggered()),this,SLOT(onEnshrine()));

    //子菜单和槽函数绑定
    connect(ui->esAction,SIGNAL(triggered()),this,SLOT(onEnshrine()));

    //查找
    findAction =new QAction(QIcon(":Find"),tr("查找"),this);
    findAction->setShortcut(tr("Ctrl+P"));
    findAction->setStatusTip(tr("剪切文件"));
    //connect(findAction,SIGNAL(triggered()),this,SLOT(onFind()));

    //设置
    setAction =new QAction(QIcon(":Set"),tr("设置"),this);
    setAction->setShortcut(tr("Ctrl+K"));
    setAction->setStatusTip(tr("设置"));
    //connect(setAction,SIGNAL(triggered()),this,SLOT(onSet()));

    //文件工具条
    fileTool = addToolBar("File");
    fileTool->setMovable(false);  //禁止移动，相当于把竖直的移动标志去掉了
    fileTool->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    fileTool->addAction(openFileAction);
    fileTool->addAction(saveAction);
    fileTool->addSeparator();  //增加分割线
    fileTool->addAction(nextAction);
    fileTool->addAction(preAction);

    //编辑工具条
    editTool = addToolBar("Edit");
    editTool->setMovable(false);  //禁止移动
    editTool->addAction(esAction);
    editTool->addAction(findAction);
    editTool->addAction(setAction);
    editTool->addSeparator();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::onEnshrine()
{
    QMessageBox::information(this, tr("提示"), tr("你点击了收藏工具栏按钮"));
}

